//
//  KZExt_ArrayAndDictionary.swift
//  KZSwiftMoudel
//
//  Created by 朱凯 on 2018/5/3.
//  Copyright © 2018年 JooKey. All rights reserved.
//

import Foundation

extension Array {
    
    /// 拓展数组的下标取值方式
    subscript (input: [Int]) -> ArraySlice<Element> {
        
        get {
            var out = ArraySlice<Element>()
            for i in input {
                if i < 0 || i >= self.count {
                    assertionFailure("数组越界")
                }
                out.append(self[i])
            }
            return out
        }
        set {
            for (index, i) in input.enumerated() {
                if i < 0 || i >= self.count {
                    assertionFailure("数组越界")
                }
                self[i] = newValue[index]
            }
        }
    }
    
    subscript (input: Int...) -> ArraySlice<Element> {
        
        get {
            var out = ArraySlice<Element>()
            for i in input {
                if i < 0 || i >= self.count {
                    assertionFailure("数组越界")
                }
                out.append(self[i])
            }
            return out
        }
        set {
            for (index, i) in input.enumerated() {
                if i < 0 || i >= self.count {
                    assertionFailure("数组越界")
                }
                self[i] = newValue[index]
            }
        }
    }
}
